package com.example.books.ui.dashboard;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.example.books.CollectionActivity;
import com.example.books.R;
import com.example.books.adapter.CollectionAdapter;

public class DashboardFragment extends Fragment {

    private DashboardViewModel dashboardViewModel;
    private ListView listCollection;
    private View root;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        dashboardViewModel =
                ViewModelProviders.of(getActivity()).get(DashboardViewModel.class);
        root = inflater.inflate(R.layout.activity_collection, container, false);
        initView();
        return root;
    }

    private void initView() {
        listCollection = (ListView) root.findViewById(R.id.listCollection);
        CollectionAdapter adapter = new CollectionAdapter(dashboardViewModel.bookList(),getContext());
        listCollection.setAdapter(adapter);
    }
}